<?php 


require "../common/Curl.php";

/**
 *	https://open.esign.cn/doc/detail?id=opendoc%2Fpaas_api%2Fsgv49u&namespace=opendoc%2Fpaas_api
 * 	电子签名SaaS API非标版
 * 	印章服务API----接口顺序排列封装
 * 
 */


$appId = "7438873193";       //应用id
$secret = "1dc4d84aeeb9698c29c57202485581b5";  //应用密钥
$grantType = "client_credentials";   //授权类型，固定值
$url = "https://smlopenapi.esign.cn";  // url沙箱环境

$token = getTokenEnd($appId,$secret,$grantType);  // 直接返回token值


$header = array(                          // header请求头信息
        'X-AjaxPro-Method:ShowList',
        'User-Agent:Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.154 Safari/537.36',
        'X-Tsign-Open-App-Id:'.$appId,
		'Content-Type:application/json',
		'charset=UTF-8',
		'X-Tsign-Open-Token:'.$token
    );

//-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

/**
 * [createSealPerson 创建个人模板印章]
 * @param  [type] $accountId [个人账号accountId]
 * @param  [type] $color     [印章颜色]
 * @param  [type] $type      [模板类型]
 * @param  [type] $alias     [印章别名]
 * @param  [type] $height    [高度]
 * @param  [type] $width     [宽度]
 * @param  [type] $header    [请求头]
 * @param  string $url       [请求地址]
 * @return [json]            [返回印章链接信息等等]
 */
function createSealPerson($accountId,$color,$type,$alias,$height,$width,$header,$url="https://smlopenapi.esign.cn"){
	$get_url = $url."/v1/accounts/".$accountId."/seals/personaltemplate";
	$data = [
		'accountId'=>$accountId,
		"color"=>$color,
	    "type"=>$type,
	    "alias"=>$alias,
	    "height"=>$height,
	    "width"=>$width
	];
	$header = $header;
	$res = send_request($get_url, $method = "POST", $data, $header);
	return $res['data'];
}
// $accountId = "a7070967395447c884c1715063b6aac7";   //用户id
// $color = "BLUE";   // 印章颜色，RED-红色  BLUE-蓝色 BLACK-黑色
// $type = "SQUARE";  //  SQUARE 正方形印章  RECTANGLE 带边框矩形印章  BORDERLESS 无边框矩形印章
// $alias = "刘颂晶的专属印章";      //印章别名
// $width = "100";
// $height = "100";    //印章宽高
// $a = createSealPerson($accountId,$color,$type,$alias,$height,$width,$header);
// var_dump($a);die;

//-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

/**
 * [createSealOrgan 创建机构模板印章]
 * @param  [type] $orgId   [机构账号orgId]
 * @param  [type] $color   [印章颜色]
 * @param  [type] $type    [模板类型]
 * @param  [type] $central [中心图案类型]
 * @param  [type] $alias   [印章别名]
 * @param  [type] $height  [高度]
 * @param  [type] $width   [宽度]
 * @param  [type] $htext   [横向文]
 * @param  [type] $qtext   [下弦文]
 * @param  [type] $header  [请求头]
 * @param  string $url     [请求地址]
 * @return [json]          [返回印章链接信息等等]
 */
function createSealOrgan($orgId,$color,$type,$central,$alias,$height,$width,$htext,$qtext,$header,$url="https://smlopenapi.esign.cn"){
	$get_url = $url."/v1/organizations/".$orgId."/seals/officialtemplate";
	$data = [
		'orgId'=>$orgId,
		"color"=>$color,
	    "type"=>$type,
	    "central"=>$central,
	    "alias"=>$alias,
	    "height"=>$height,
	    "width"=>$width,
	    "htext"=>$htext,
	    "qtext"=>$qtext
	];
	$header = $header;
	$res = send_request($get_url, $method = "POST", $data, $header);
	return $res['data'];
}
// $orgId = "aba7702a0fc64f7d99ee158e3767421a";   //机构id
// $color = "RED";   // 印章颜色，RED-红色  BLUE-蓝色 BLACK-黑色
// $type = "TEMPLATE_ROUND";  //  TEMPLATE_ROUND 圆章   TEMPLATE_OVAL 	椭圆章 
// $central = "STAR";     // STAR 圆形有五角星   NONE 圆形无五角星
// $alias = "刘颂晶机构的专属印章";      //印章别名
// $width = "100";
// $height = "100";    //印章宽高
// $htext = "lsj";  // 横向文
// $qtext = "刘颂晶科技有限公司"; //下弦文
// $a = createSealOrgan($orgId,$color,$type,$central,$alias,$height,$width,$htext,$qtext,$header);
// var_dump($a);die;

//-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------


function createSealImage($accountId,$type,$data,$alias,$height,$width,$transparentFlag,$header,$url="https://smlopenapi.esign.cn"){
	$get_url = $url."/v1/organizations/".$orgId."/seals/officialtemplate";
	$datares = [
		'accountId'=>$accountId,
	    "type"=>$type,
	    "data"=>$data,
	    "alias"=>$alias,
	    "height"=>$height,
	    "width"=>$width,
	    "transparentFlag"=>$transparentFlag
	];
	$data = $datares;
	$header = $header;
	$res = send_request($get_url, $method = "POST", $data, $header);
	return $res['data'];
}






